package com.atguigu.stgy.admin.service.impl;

import com.atguigu.stgy.admin.service.ApartmentLabelService;
import com.atguigu.stgy.model.dto.ApartmentDTO;
import org.springframework.stereotype.Service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.stgy.admin.mapper.ApartmentLabelMapper;
import com.atguigu.stgy.model.entity.ApartmentLabel;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ApartmentLabelServiceImpl extends ServiceImpl<ApartmentLabelMapper, ApartmentLabel> implements ApartmentLabelService {
    public void bathSaveLabel(ApartmentDTO apartmentDTO, Long apartmentInfoId) {

        if (CollectionUtils.isEmpty(apartmentDTO.getLabelIds())){
            return ;
        }
        List<ApartmentLabel> labels = apartmentDTO.getLabelIds().stream().map(labelId -> {

            ApartmentLabel apartmentLabel = new ApartmentLabel();
            apartmentLabel.setApartmentId(apartmentInfoId);
            apartmentLabel.setLabelId(labelId);
            return apartmentLabel;
        }).collect(Collectors.toList());

        this.saveBatch(labels);
    }

}
